#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
class Solution
{
public:
    int distributeCandies(vector<int> &candyType)
    {
        unordered_set<int> typeSet;
        for (int candy : candyType)
        {
            typeSet.emplace(candy);
        }
        return candyType.size() / 2 >= typeSet.size() ? typeSet.size() : candyType.size() / 2;
    }

    int distributeCandies_2(vector<int> &candyType)
    {
        int size = candyType.size();
        bool a[200001]{false};

        int count = 0;
        for (int x : candyType)
        {
            if (!a[x + 100000])
            {
                a[x + 100000] = true;
                count++;
                if (count >= size / 2)
                {
                    break;
                }
            }
        }
        return count;
    }

    int distributeCandies_3(vector<int> &candyType)
    {
        return min(unordered_set<int>(candyType.begin(), candyType.end()).size(), candyType.size() / 2);
    }
};
int main()
{
    Solution s;
    vector<int> candyType = {6, 6, 6, 6};
    cout << s.distributeCandies(candyType) << endl;
    system("pause");
    return 0;
}
